package org.squabble.web.data;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.squabble.domain.Account;
import org.squabble.service.SearchService;

@Controller
public class AccountList {

	@Autowired
	SearchService searchService;

	@PreAuthorize("hasRole('ROLE_ADMIN')")
	@RequestMapping(value = "/data/admin/accounts", method = RequestMethod.GET)
	public List<Account> accountList(@RequestParam(value = "term") String search,
			ModelMap model, HttpServletRequest request) {
		List<Account> accounts = searchService.getAccounts(search);
		return accounts;
	}


}
